home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / editors / AME / Rexx / vreplace.ame < prev    next >
Encoding:
Text File  |  1994-02-01  |  3.8 KB  |  169 lines

  1. /*   $VER: VReplace 37.1 (21.2.93) */
  2. /*   This program brings up a Find/Change Requester for AME */
  3.  
  4. if show("l", "rexxarplib.library") = 0 then do
  5.    check = addlib('rexxsupport.library', 0, -30, 0)
  6.    check = addlib('rexxarplib.library',  0, -30, 0)
  7. end
  8.  
  9. options results
  10.  
  11. /*
  12. *   The following sequence determines both AME's screen and port name,
  13. *   and also gets the number screen rows and columns.
  14. */
  15.  
  16. ameport = address()
  17. cols = ScreenCols(ameport)
  18. if cols == -1 then do
  19.    amescreen = ""
  20.    cols = ScreenCols()
  21.    rows = ScreenRows()
  22. end
  23. else do
  24.    amescreen = ameport
  25.    rows = ScreenRows(amescreen)
  26. end
  27. /*
  28.  *   Set up a host. This time, send all messages to our own port.
  29.  */
  30.  
  31. address AREXX "'x = CreateHost(AMEREPLACE, REPLACEPORT, "amescreen")'"
  32. /*
  33.  *   Wait until it is ready.
  34.  */
  35. do i = 1
  36.    if showlist('p', AMEREPLACE) ~= 0 then leave
  37.    call delay 30
  38. end
  39.  
  40. /*
  41.  *   Open the window
  42.  */
  43.  
  44. idcmp = 'CLOSEWINDOW+GADGETUP'
  45. flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
  46.  
  47. call OpenWindow(AMEREPLACE, (cols - 640)/2, rows - 190, 600, 120, idcmp,   ,
  48.                 flags, "Replace...")
  49.  
  50. /*
  51.  *   Open the port that messages will come to
  52.  */
  53. mp = openport(REPLACEPORT)
  54.  
  55.  
  56. /*
  57.  *   Read the current search settings
  58.  */
  59. 'getlastpattern'
  60. findstring = result
  61. "getprefs" "case"
  62. caseflag = result
  63. "getprefs" "regex"
  64. regexflag = result
  65.  
  66. replacestring = ""
  67.  
  68. /*
  69.  *   Add the gadgets
  70.  */
  71.  
  72. call AddGadget(AMEREPLACE, 50,   28, 2, findstring, "%d%1%g", 160, RIDGEBORDER)
  73. call AddGadget(AMEREPLACE, 360,  28, 0, "  ", "%d")
  74. call AddGadget(AMEREPLACE, 360,  46, 1, "  ", "%d")
  75. call AddGadget(AMEREPLACE, 50,   46, 5, "", "%d%1%g", 160, RIDGEBORDER)
  76. call AddGadget(AMEREPLACE, 110,  64, 4, "Again", "%d")
  77.  
  78. Call Move(AMEREPLACE,220,34)
  79. Call Text(AMEREPLACE,"Search String")
  80. Call Move(AMEREPLACE,220,52)
  81. Call Text(AMEREPLACE,"Replace String")
  82.  
  83. Call Move(AMEREPLACE,400,34)
  84. call Text(AMEREPLACE, "Case Sensitive")
  85. Call Move(AMEREPLACE,400,52)
  86. call Text(AMEREPLACE, "Regular Expression")
  87.  
  88. call AddGadget(AMEREPLACE, 50, 84, "USE",   "\    OK    \  ", "USE")
  89. call AddGadget(AMEREPLACE,450, 84, "CLOSE", "\   Cancel  \  ", "CANCEL")
  90.  
  91. /* set things up for the cancel */
  92.  
  93. uncase = 'unsetprefs'
  94. unregex = 'unsetprefs'
  95.  
  96. /*
  97.  *   set gadgets that should be on
  98.  */
  99.  
  100. if compare(caseflag,"CASE") = 0 then do
  101.     res = SetGadget(AMEREPLACE, 0, "ON")
  102.     uncase = 'setprefs'
  103.     end
  104.  
  105. if compare(regexflag,"REGEX") = 0 then do
  106.     res = SetGadget(AMEREPLACE, 1, "ON")
  107.     unregex = 'setprefs'
  108.     end
  109.  
  110. /*
  111.  *   Main event loop
  112.  */
  113. quitflag  = 0
  114.  
  115.  
  116. do forever
  117.     if quitflag = 1 then leave
  118.     t = waitpkt(REPLACEPORT)
  119.     do forever
  120.         p = getpkt(REPLACEPORT)
  121.           if c2d(p) = 0 then leave
  122.           cmd = getarg(p)
  123.           if cmd = "2" then findstring = getarg(p,1)
  124.           if cmd = "5" then replacestring = getarg(p,1)
  125.           t = reply(p, 0)
  126.  
  127.           /* process the command */
  128.  
  129.           if cmd = "CANCEL" then do
  130.             call CloseWindow(AMEREPLACE)
  131.         uncase "CASE"
  132.         unregex "REGEX"
  133.             quitflag = 1
  134.             end
  135.           else if cmd = "USE" | cmd = "CLOSEWINDOW" then do
  136.             call CloseWindow(AMEREPLACE)
  137.             quitflag = 1
  138.             end
  139.           else if cmd = "5" | cmd = "4" then do
  140.         'findchange' '-f' 1 '-n' 1 findstring || '*N' || replacestring || '*N'
  141.             end
  142.         else if cmd = "0" then do
  143.         if compare(caseflag,"CASE") = 0 then do
  144.             call SetGadget(AMEREPLACE, cmd, "OFF")
  145.             'unsetprefs' "CASE"
  146.             end
  147.         else do
  148.             call SetGadget(AMEREPLACE, cmd, "ON")
  149.             'setprefs' "CASE"
  150.             end
  151.         'getprefs' "CASE"
  152.         caseflag = result
  153.             end
  154.           else if cmd = "1" then do
  155.         if compare(regexflag,"REGEX") = 0 then do
  156.             call SetGadget(AMEREPLACE, cmd, "OFF")
  157.             'unsetprefs' "REGEX"
  158.             end
  159.         else do
  160.             call SetGadget(AMEREPLACE, cmd, "ON")
  161.             'setprefs' "REGEX"
  162.             end
  163.         'getprefs' "REGEX"
  164.         regexflag = result
  165.             end
  166.         end
  167.    end
  168.  
  169. exit